import { useLayoutEffect } from "react";
import { Outlet, useLoaderData } from "react-router-dom";

import { router, searchRoute, useLocation } from "@/router/Router";

const App = () => {
	const { pathname } = useLocation();

	const data = useLoaderData();
	useLayoutEffect(() => {
		console.log(data);
		// APP作为跟组件，路由监听跟token校验都可以放在这里面统一处理
		const routeList = router?.routes ?? [];
		const { meta } = searchRoute(pathname, routeList) ?? {};
		document.title = meta?.title ?? "";
	}, [data, pathname]);
	return <Outlet />;
};
export default App;
